package com.zhj.network.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @PackageName:com.zhj.network.udp
 * @ClassName:UdpClientDemo01
 * @auter: 朱慧杰
 * @date:2020/7/21 0021 13:24
 **/
public class UdpClientDemo01 {

    public static void main(String[] args) throws Exception {
        // 1. 建立一个Socket
        DatagramSocket socket = new DatagramSocket();

        // 数据
        String msg = "你好啊，服务器！";
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9090;

        // 2.数据包包
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, localhost, port);
        // 3.发送包
        socket.send(packet);

        socket.close();
    }

}
